package SpringBoot.spring_boot_starter_security.D03_权限校验.config.handler;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler;

import com.titan.core.utils.io.ConsoleUtils;
import com.titan.core.web.utils.RequestUtils;

/**
 *
 *
 * @author 周成功
 *
 */
public class LoginSuccessHandler extends SavedRequestAwareAuthenticationSuccessHandler {
    @Override
    public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
            Authentication authentication) throws IOException, ServletException {
        // 获得授权后可得到用户信息 可使用SUserService进行数据库操作
        Object userDetails = authentication.getPrincipal();
        ConsoleUtils.log("LoginSuccessHandler", "Principal", userDetails);
        System.out.println(userDetails);
//        SysUser userDetails = (SysUser)authentication.getPrincipal();
        /* Set<SysRole> roles = userDetails.getSysRoles(); */
        // 输出登录提示信息
//        System.out.println("管理员 " + userDetails.getName() + " 登录");
//        System.out.println("IP :" + RequestUtils.getRemortIP(request));

        super.onAuthenticationSuccess(request, response, authentication);
    }
}
